Removing an old, cherished, yet pointless caveat "This documentation is
[supercollider.git] / Help / Streams-Patterns-Events / A Practical Guide / PG_Cookbook04_Sending_MIDI.html
blobfd882edad7b3499837288df1cb339a799dc70dc0
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.48">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0000bf}
18 span.s1 {color: #0000bf}
19 span.s2 {color: #007300}
20 span.s3 {color: #0000bf}
21 span.s4 {color: #000000}
22 span.s5 {color: #606060}
23 span.s6 {color: #007300}
24 span.s7 {font: 12.0px Helvetica}
25 span.Apple-tab-span {white-space:pre}
26 </style>
27 </head>
28 <body>
29 <p class="p1"><b>Sending MIDI out with Patterns</b></p>
30 <p class="p2"><br></p>
31 <p class="p3">Sending MIDI is the job of the <a href="../../Control/MIDIOut.html"><span class="s1">MIDIOut</span></a> class and the \midi event type. A MIDIOut is created to talk to a hardware device; the MIDI channel is provided when an event is played. MIDIOut's newByName makes it easier to identify a device.</p>
32 <p class="p2"><br></p>
33 <p class="p3">The \midi event type supports the following commands, chosen in the event by the \midicmd key: <span class="s2">\allNotesOff</span>, <span class="s2">\bend</span>, <span class="s2">\control</span>, <span class="s2">\noteOff</span>, <span class="s2">\noteOn</span>, <span class="s2">\polyTouch</span>, <span class="s2">\program</span>, <span class="s2">\smpte</span>, <span class="s2">\songPtr</span>, <span class="s2">\sysex</span>, <span class="s2">\touch</span>. The default is \noteOn. When playing a note (noteOn), by default the corresponding noteOff message will be sent after the note's sustain time.</p>
34 <p class="p2"><br></p>
35 <p class="p3">If you want to synchronize events played by a MIDI device and events played by the SuperCollider server, the MIDIOut object's latency must match the server latency. You can set the latency any time to affect all future events.</p>
36 <p class="p2"><br></p>
37 <p class="p4"><span class="s3">MIDIClient</span><span class="s4">.init;<span class="Apple-tab-span"> </span></span>// if not already done</p>
38 <p class="p5"><br></p>
39 <p class="p6">(</p>
40 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span></span>// substitute your own device here</p>
41 <p class="p6"><span class="s3">var</span><span class="Apple-tab-span"> </span>mOut = <span class="s3">MIDIOut</span>.newByName(<span class="s5">"FastLane USB"</span>, <span class="s5">"Port A"</span>).latency_(<span class="s3">Server</span>.default.latency);</p>
42 <p class="p5"><br></p>
43 <p class="p6">p = <span class="s3">Pbind</span>(</p>
44 <p class="p7"><span class="s4"><span class="Apple-tab-span"> </span></span>\type<span class="s4">, </span>\midi<span class="s4">,</span></p>
45 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// this line is optional b/c noteOn is the default</p>
46 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// just making it explicit here</p>
47 <p class="p7"><span class="s4"><span class="Apple-tab-span"> </span></span>\midicmd<span class="s4">, </span>\noteOn<span class="s4">,</span></p>
48 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span></span><span class="s6">\midiout</span><span class="s4">, mOut,<span class="Apple-tab-span"> </span></span>// must provide the MIDI target here</p>
49 <p class="p6"><span class="Apple-tab-span"> </span><span class="s6">\chan</span>, 0,</p>
50 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// degree is converted to midinote, not just frequency</p>
51 <p class="p6"><span class="Apple-tab-span"> </span><span class="s6">\degree</span>, <span class="s3">Pwhite</span>(-7, 12, <span class="s3">inf</span>),</p>
52 <p class="p6"><span class="Apple-tab-span"> </span><span class="s6">\dur</span>, <span class="s3">Pwrand</span>([0.25, <span class="s3">Pn</span>(0.125, 2)], #[0.8, 0.2], <span class="s3">inf</span>),</p>
53 <p class="p6"><span class="Apple-tab-span"> </span><span class="s6">\legato</span>, sin(<span class="s3">Ptime</span>(<span class="s3">inf</span>) * 0.5).linexp(-1, 1, 1/3, 3),</p>
54 <p class="p6"><span class="Apple-tab-span"> </span><span class="s6">\amp</span>, <span class="s3">Pexprand</span>(0.5, 1.0, <span class="s3">inf</span>)</p>
55 <p class="p6">).play(quant: 1);</p>
56 <p class="p6">)</p>
57 <p class="p5"><br></p>
58 <p class="p6">p.stop;</p>
59 <p class="p2"><br></p>
60 <p class="p2"><br></p>
61 <p class="p8"><span class="s4">Previous:<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><a href="PG_Cookbook03_External_Control.html"><span class="s7">PG_Cookbook03_External_Control</span></a></span></p>
62 <p class="p8"><span class="s4">Next:<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><a href="PG_Cookbook05_Using_Samples.html"><span class="s7">PG_Cookbook05_Using_Samples</span></a></span></p>
63 </body>
64 </html>